<?php

namespace App\Trip\Orders\BookOrders\Train\Order\AbstractOrder;

use App\Models\Train\TrainOrders\TrainOrder;
use App\Trip\Orders\BookOrders\Params\AbstractOrderParam\AbstractOrderParam;
use App\Trip\Orders\BookOrders\Params\AbstractOrderParam\AbstractSnapOrderParam;
use App\Trip\Orders\BookOrders\Params\AbstractParam\AbstractParam;
use App\Trip\Orders\BookOrders\Params\PassengersParam;
use App\Trip\Orders\BookOrders\Train\Passengers\AbstractOrderPassenger\AbstractOrderPassengers;
use App\Trip\Orders\BookOrders\Train\PriceDetails\AbstractPriceDetails\AbstractPriceDetails;
use App\Trip\Orders\BookOrders\Train\SelectedSeats\SelectedSeats;
use JetBrains\PhpStorm\ArrayShape;

abstract class AbstractBuildOrderInfo
{

    protected AbstractOrderParam $order_param;
    protected AbstractParam      $param;
    protected PassengersParam    $passenger_param;
    protected SelectedSeats      $selected_seats;

    /**
     * 构造订单数据
     *
     * @return array
     *
     */

    #[ArrayShape([
        'trip_id'                  => "string",
        'order_sn'                 => "string",
        'out_order_sn'             => "string",
        'user_id'                  => "string",
        'transfer_flag'            => "int",
        'trip_no'                  => "int",
        'order_service'            => "string",
        'online'                   => "int",
        'out_order_id'             => "string",
        'trip_type'                => "int",
        'order_state'              => "int",
        'change_flag'              => "int",
        'order_amount'             => "float",
        'receivable'               => "float",
        'origin_order_need_refund' => "float",
        'train_info'               => "array",
        'passengers'               => "array",
        'price_details'            => "array",
        'selected_seats'           => "string",
    ])]
    public abstract function buildOrderInfo(): array;

    public abstract function getOriginOrderInfo(): ?TrainOrder;

    public abstract function priceDetailsBuilder(): AbstractPriceDetails;

    /**
     * 主行程
     *
     * @return array
     */
    public abstract function getTrainInfo(): array;

    /**
     * 选座
     *
     */
    public function getSelectedSeats(): SelectedSeats
    {
        return $this->selected_seats;
    }

    public function passengers(): array
    {
        return $this->passengerBuilder()->buildPassengers();
    }

    public abstract function passengerBuilder(): AbstractOrderPassengers;

    public function getOrderParam(): AbstractOrderParam|AbstractSnapOrderParam
    {
        return $this->order_param;
    }

    public function getPassengerParam(): PassengersParam
    {
        return $this->passenger_param;
    }

    /**
     * 检测 , 如行程冲突 , 是否能改签等
     *
     * @return void
     */
    protected abstract function check(): void;
}